package com.kuaimacode.kframework.api.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kuaimacode.kframework.common.Constant;
import com.kuaimacode.kframework.mybatis.mapper.agent.SysAgentCategoryCfgMapper;
import com.kuaimacode.kframework.mybatis.models.agent.SysAgentCategoryCfg;
import com.kuaimacode.kframework.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 分站物品品类设置 服务实现类
 * </p>
 *
 * @author Bean
 * @since 2019-03-12
 */
@Service
public class SysAgentCategoryCfgService extends ServiceImpl<SysAgentCategoryCfgMapper, SysAgentCategoryCfg> {


    /**
     * 查询分站帮我取物品品类信息
     * @param agentId 分站id
     * @param type 1帮我送 2 帮我取 3 随意购 4 上门技术服务
     * @return
     */
    public List<SysAgentCategoryCfg> getCategoryByType(String agentId,String type) {
        QueryWrapper<SysAgentCategoryCfg> qryWrapper = new QueryWrapper<>();
//        if(agentId ==null||"".equals(agentId)) agentId = "000000";
        qryWrapper.eq("agent_id", agentId);
        qryWrapper.eq("delete_state", "0");
        if(type!=null &&!"".equals(type)){
            qryWrapper.eq("type", type);
        }

        List<SysAgentCategoryCfg> categoryList = baseMapper.selectList(qryWrapper);

//        if(categoryList==null || categoryList.size()<1){
//            QueryWrapper<SysAgentCategoryCfg> wrapper = new QueryWrapper<>();
//            wrapper.eq("agent_id", "000000");
//            wrapper.eq("delete_state", "0");
//            if(type!=null &&!"".equals(type)){
//                wrapper.eq("type", type);
//            }
//            categoryList = baseMapper.selectList(wrapper);
//        }
        return categoryList;
    }


    public SysAgentCategoryCfg getAgentCategoryByCatagory(String agentId,String type,String catagory) {
        QueryWrapper<SysAgentCategoryCfg> qryWrapper = new QueryWrapper<>();
//        if(agentId ==null||"".equals(agentId)) agentId = "000000";
        qryWrapper.eq("agent_id", agentId);
        qryWrapper.eq("delete_state", "0");
        if(type!=null &&!"".equals(type)){
            qryWrapper.eq("type", type);
        }
        if (StringUtils.isNotBlank(catagory)){
            qryWrapper.eq("category",catagory);
        }
        return baseMapper.selectOne(qryWrapper);
    }
}
